package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * JDBC中的事务控制
 */
public class JDBCDemo11 {
    public static void main(String[] args) {
        try(Connection connection=DBUtil.getConnection();) {
            connection.setAutoCommit(false);//关闭自动提交
            //设置事务隔离级别
            connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
            String sql="UPDATE user2 SET password=? WHERE username=?";
            PreparedStatement ps=connection.prepareStatement(sql);
            ps.setString(1,"123456");
            ps.setString(2,"王克晶");
            int num=ps.executeUpdate();
            System.out.println(num>0?"成功":"失败");
            connection.commit();
//            connection.rollback();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
